package com.eascs.ticket.schedule.controller;

import java.text.Format;
import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eascs.site.page.CellWidthFormat;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.view.ViewContext;
import com.eascs.site.view.button.Button;
import com.eascs.site.view.button.ButtonHelper;
import com.eascs.ticket.common.controller.BaseMasterViewController;
import com.eascs.ticket.common.form.IdForm;
import com.eascs.ticket.common.form.PageForm;
import com.eascs.ticket.schedule.entity.ScheduleTicket;
import com.eascs.ticket.schedule.service.ScheduleTicketOperatorService;
import com.eascs.ticket.schedule.service.ScheduleTicketService;

@Controller
public class ScheduleTicketViewController extends BaseMasterViewController {
	@Inject
	private ScheduleTicketService scheduleTicketService;

	@Inject
	private ScheduleTicketOperatorService scheduleTicketOperatorService;

	@RequestMapping(value = "/schedule/view/viewScheduleTicketList")
	public String viewScheduleTicketList(PageForm pageForm) {
		List<Object[]> allScheduleTickets = scheduleTicketService.getAllScheduleTickets();
		PaginationInfo allScheduleTicketsPaginationInfo = new PaginationInfo(allScheduleTickets, new String[] { "标题", "类型", "到期天数", "自动创建周期", "状态", "模块", "修改时间", "创建时间", "修改人", "创建人" });
		allScheduleTicketsPaginationInfo.setMoreButtons(new Button[] { ButtonHelper.createOpenButton("查看", "/schedule/view/viewScheduleTicket?id=") });
		allScheduleTicketsPaginationInfo.setBuildPagingNavigation(false);
		allScheduleTicketsPaginationInfo.setFormats(new Format[] { new CellWidthFormat(200) });
		ViewContext.put("allScheduleTicketsPaginationInfo", allScheduleTicketsPaginationInfo);
		return "/schedule/viewScheduleTicketList";
	}

	@RequestMapping(value = "/schedule/view/viewScheduleTicket")
	public String viewScheduleTicket(IdForm idForm) {
		ScheduleTicket scheduleTicket = scheduleTicketService.getScheduleTicketById(idForm.getId());
		ViewContext.put("scheduleTicket", scheduleTicket);
		PaginationInfo scheduleTicketOperatorsPaginationInfo = new PaginationInfo(scheduleTicketOperatorService.getScheduleTicketOperatorsByScheduleTicketId(scheduleTicket.getId()), new String[] { "人员" });
		scheduleTicketOperatorsPaginationInfo.setMoreButtons(new Button[] { ButtonHelper.createAjaxConfirmButton("删除", "/schedule/rest/removeScheduleTicketOperator?id=") });
		scheduleTicketOperatorsPaginationInfo.setBuildPagingNavigation(false);
		ViewContext.put("scheduleTicketOperatorsPaginationInfo", scheduleTicketOperatorsPaginationInfo);
		return "/schedule/viewScheduleTicket";
	}
}
